﻿using UnityEngine;
using System.Collections;

public class TestCardAttack : MonoBehaviour {
	
	public bool bActivate;
	public bool bAttackEventTriggered;
	public bool isRightSide;
	public bool m_bScaleBack;
	// Use this for initialization
	public float scaleModOriginal = 1.25f;
	public float attackRange = 45.0f;
	public float [] timeOffset;
	public float [] waitTime;
	void Start () {
		
	}
	
//	void AttackEvent()
//	{
//		glog.debug("card attack event");
//		bAttackEventTriggered = true;
//	}
//	
//	void ScaleBackDone()
//	{
//		glog.debug("scale back done");
//		bAttackEffectDone = true;
//	}
	
	IEnumerator Attack()
	{
		//bAttackEffectDone = false;
		float scaleMod = scaleModOriginal;
		iTween.ScaleBy( gameObject , iTween.Hash("time", timeOffset[0], "amount", new Vector3(scaleMod,scaleMod,1.0f) , "islocal", true, "easetype","easeOutQuad" )  );
		yield return new WaitForSeconds(waitTime[0]);
		Vector3 originalPos = transform.localPosition;
		Vector3 destPos = originalPos;
		
		if(isRightSide)
			destPos.x -= attackRange;
		else
			destPos.x += attackRange;
		
		iTween.MoveTo( gameObject , iTween.Hash("time", timeOffset[1], "position", destPos , "islocal", true, "easetype","easeOutElastic" )  );
		
		/*
		yield return new WaitForSeconds(waitTime[1]);
		iTween.MoveTo( gameObject , iTween.Hash("time", timeOffset[2], "position", originalPos , "islocal", true, "easetype","easeInSine" )  );
		//yield return new WaitForSeconds(0.1f);
		//if(m_bScaleBack)
		//{
		//	scaleMod = 1/scaleModOriginal;
		if(m_bScaleBack)
			iTween.ScaleTo( gameObject , iTween.Hash("time", timeOffset[3], "x",1,"y",1 , "islocal", false, "easetype","easeInSine" )  );
		//}
		
		*/
	}
	
	public void SetActivate(bool bScaleBack)
	{
		m_bScaleBack = bScaleBack;
		bActivate = true;
	}
	
	// Update is called once per frame
	void Update () {
		if(bActivate)
		{
			bActivate = false;
			bAttackEventTriggered = false;
			StartCoroutine("Attack");
		}
	}
}
